<template>
  <view class="addBank">
    <view class="addBank-warp">
      <view class="account-item" v-if="formLine.type == 'weixin'">
        <view class="account-item-title">
          微信账号
        </view>
        <input type="text" class="ipt" v-model="formLine.cash_weixin" placeholder="请输入" placeholder-class="styles">
      </view>
      <view class="account-item" v-if="formLine.type == 'alipay'">
        <view class="account-item-title">
          支付宝账号
        </view>
        <input type="text" class="ipt" v-model="formLine.cash_alipay_code" placeholder="请输入" placeholder-class="styles">
      </view>
      <view class="account-item">
        <view class="account-item-title">
          姓名
        </view>
        <input type="text" class="ipt" v-model="formLine.cash_name" placeholder="请输入" placeholder-class="styles">
      </view>
<!--      <view class="uploadBlock" v-if="formLine.type != 'bank'">
        <view class="uploadTitle">
          收款码
        </view>
        <view class="imgs">
          <UploadImg keyName="extract_pic" :uploadImg="formLine.extract_pic" @getUrl="getUrl" />
        </view>
      </view> -->
    </view>
    <view class="footer">
      <view class="btn" @click="onSave">保存</view>
    </view>
  </view>
</template>
<script>
  import reqApi from "../../api/api.js";
  export default {
    data() {
      return {
        titleInfo: {
          weixin: "微信账户",
          alipay: "支付宝账号"
        },
        formLine: {
          type: "", //bank银行卡，weixin微信，alipay支付宝
          cash_weixin: "",
          cash_alipay_code: "",
          cash_name: "",
        }
      }
    },
    onLoad(option) {
      uni.setNavigationBarTitle({
        title: this.titleInfo[option.type]
      });
      this.formLine.type = option.type;
      let accountInfo = uni.getStorageSync("accountInfo");
      console.log("accountInfo", accountInfo);
      if (option.type == "alipay") {
        this.formLine.cash_alipay_code = accountInfo.cash_alipay_code;
      }
      if (option.type == "weixin") {
        this.formLine.cash_weixin = accountInfo.cash_weixin;
      }
    },
    methods: { 
      // getUrl(e) {
      //   console.log("子组件传过来的", e);
      //   const {
      //     keyName,
      //     value
      //   } = e;
      //   this.formLine[keyName] = value;
      // },
      onSave() {
        reqApi.extractAccount(this.formLine).then(res => {
          uni.showToast({
            title: "保存成功",
            duration: 1500,
            icon: 'none',
            mask: true
          })
          setTimeout(() => {
            uni.navigateBack({delta: 1})
          }, 1500)
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .uploadBlock {
    padding: 30rpx;
    box-sizing: border-box;

    .uploadTitle {
      font-family: PingFang SC, PingFang SC;
      font-weight: 400;
      font-size: 30rpx;
      margin-bottom: 30rpx;
    }
  }

  .footer {
    padding: 0 70rpx;
    box-sizing: border-box;
    position: fixed;
    bottom: 30rpx;
    width: 100%;

    .btn {
      width: 100%;
      height: 88rpx;
      background: #F86F03;
      border-radius: 88rpx;
      font-family: PingFang SC, PingFang SC;
      font-weight: bold;
      font-size: 32rpx;
      color: #FFFFFF;
      text-align: center;
      line-height: 88rpx;
    }
  }

  .addBank {
    background: #fff;

    .addBank-warp {
      .account-item {
        padding: 30rpx;
        box-sizing: border-box;
        border-bottom: 2rpx solid #eee;

        .account-item-title {
          font-family: PingFang SC, PingFang SC;
          font-weight: 400;
          font-size: 30rpx;
          color: #333333;
          margin-bottom: 20rpx;
        }

        .ipt {
          font-family: PingFang SC, PingFang SC;
          font-weight: 400;
          font-size: 30rpx;
          color: #222;
        }

        .styles {
          font-family: PingFang SC, PingFang SC;
          font-weight: 400;
          font-size: 30rpx;
          color: #999999;
        }
      }
    }
  }
</style>